package com.lanou.controller;

import com.lanou.entity.Goods;
import com.lanou.service.GoodsService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName GoodsController
 * @Description TODO
 * @Author cuipengwei
 * @Date 2025年08月22日 19:42
 * @Version 1.0
 */
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    //查找全部
    @GetMapping
    public R getAll(){
        List<Goods> all = goodsService.findAll();
        return R.ok(all);
    }
    //根据id查找
    @GetMapping("{id}")
    public R getById(@PathVariable("id") Integer id){
        Goods byId = goodsService.findById(id);
        return R.ok(byId);
    }
}
